/*
 * @Description:
 * @Author: hui
 * @Date: 2021-03-03 09:25:05
 * @LastEditTime: 2021-11-15 18:04:50
 */
import store from '@/store/user/index';

export default {
	'hasPermi': {
		mounted(el: any, binding: any) {
			const { value } = binding;
			const permissions = store.state.powerList;
			if (value) {
				const hasPermissions = permissions.some((permission: string) => permission === value);
				if (!hasPermissions) {
					el.parentNode && el.parentNode.removeChild(el);
				}
			}
		}
	},
	'auto': {
		mounted(el: any, bindings: any) {
			if (!bindings.value) {
				return;
			}
			let { offsetWidth } = el;
			let contentWidth = el.scrollWidth;
			el.addEventListener(
				`mouseenter`,
				() => {
					offsetWidth = el.offsetWidth;
					contentWidth = el.scrollWidth;
					setTimeout(() => {
						const id = el.getAttribute(`aria-describedby`);
						const tooltip: any = document.querySelector(`#${id}`);
						if (tooltip && contentWidth <= offsetWidth) {
							tooltip.style.visibility = `hidden`;
						} else {
							tooltip.style.visibility = `visible`;
						}
					}, 10);
				},
				false
			);
		}
	}
};
